<template>
	<view>
		<u-mask :show="show" >
			<view class="empty" @click="close">
				<view class="txt"> 
					恭喜你获得洗车优惠{{num}}次
				</view>
				<image style="width:500rpx ;height: 600rpx;" src="/static/getCoupond.png" mode="aspectFill"></image>
			</view>
		</u-mask>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				show:false,
				num:""
			}
		},
		onLoad(options) {
			
			if (options.q) {
				let url=decodeURIComponent(options.q);
				let params=this.getQueryString(url);
				this.get(params.id)
			}
		},
		methods:{
			get(id){
				this.$u.post('/api/indent/buyCard',{
					card_id:id
				}).then(res=>{
					this.show=true;
					this.num=res.useNum;
				}).catch(err=>{
					
				})
			},
			getQueryString(url) {
			  let requestParams = {};
			  if (url.indexOf("?") !== -1) {
				let str = url.substr(url.indexOf("?") + 1); //截取?后面的内容作为字符串
				let strs = str.split("&"); //将字符串内容以&分隔为一个数组
				for (let i = 0; i < strs.length; i++) {
				  requestParams[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
				  // 将数组元素中'='左边的内容作为对象的属性名，'='右边的内容作为对象对应属性的属性值
				}
			  }
			  return requestParams;
			},
			close(){
				uni.switchTab({
					url:'/pages/index/index'
				})
			}
		}
	}
</script>

<style>
	.txt{
		position: absolute;
		top: 0;
		z-index: 999;
		width: 300rpx;
		text-align: center;
		margin:220rpx auto;
		left: 100rpx;
		background: #C66100;
		color: #fff;
		padding:  15rpx 0;
		border-radius: 40rpx;
		font-size: 26rpx;
		
	}
</style>
